package cn.flightcloud.boot.user.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flightcloud.boot.user.entity.User;
import cn.flightcloud.boot.user.service.UserService;

@RestController
public class UserController {

	private final UserService userService;
	
	private static Logger LOGGER = LoggerFactory.getLogger(UserController.class);

	@Autowired
	public UserController(UserService userService) {
		super();
		this.userService = userService;
	}
	
	@RequestMapping({"","index"})
	public String user() {
		LOGGER.info("xxxxx");
		return "index";
	}

	@RequestMapping("test")
	public String test() {
		System.out.println(userService);
		return "hello world!";
	}
	
	@RequestMapping("add")
	public String add(User user) {
		System.out.println(userService);
		userService.save(user);
		return "hello world!";
	}

	@RequestMapping("user/{name}")
	public User user(@PathVariable String name) {
		User user = new User();
		user.setName(name);
		return user;
	}
}
